package com.sneaker.shower.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sneaker.shower.common.ThreadLocalCache;
import com.sneaker.shower.entity.domain.menu.MenuImageDO;
import com.sneaker.shower.entity.dto.MenuImageDTO;
import com.sneaker.shower.mapper.MenuImageMapper;
import com.sneaker.shower.mapstruct.MenuImageMapStruct;
import com.sneaker.shower.service.MenuImageService;
import org.springframework.stereotype.Service;

/**
 * @author Hechangjian
 * @version 1.0
 * @className MenuImageServiceImpl
 * @date 2019/08/07 10:54
 * @description
 * @program bath
 */
@Service
public class MenuImageServiceImpl extends ServiceImpl<MenuImageMapper, MenuImageDO> implements MenuImageService {

    @Override
    public MenuImageDTO getByGuidAndType(Integer type, Long guid) {
        MenuImageDO menuImageDO;
        if (guid != null) {
            menuImageDO = getById(guid);
        } else {
            menuImageDO = getOne(new LambdaQueryWrapper<MenuImageDO>().eq(MenuImageDO::getGuid, type).eq(MenuImageDO::getOrganizationGuid, ThreadLocalCache.get().getOrganizationGuid()));
        }
        return MenuImageMapStruct.INSTANCE.do2DTO(menuImageDO);
    }
}
